package com.calculator;

import com.calculator.R;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.text.Editable;

public class Main extends Activity {
	EditText FirstValue;
	EditText SecondValue;
	TextView Result;
	Button multiply;
	Button add;
	Button subtract;
	Button divide;
	
	float num1 , num2;	
    
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        FirstValue = (EditText) findViewById(R.id.EditText01);
        
        SecondValue = (EditText) findViewById(R.id.EditText02);
        
        Result = (TextView) findViewById(R.id.TextView01);

        Result.setText("0.00");
        
        multiply = (Button) findViewById(R.id.Button01);
        add = (Button) findViewById(R.id.Button02);
        subtract = (Button) findViewById(R.id.Button03);
        divide = (Button) findViewById(R.id.Button04);

        //Adding listener to button
        multiply.setOnClickListener(new View.OnClickListener() {
	    	public void onClick(View v) {
	    		//Getting first & second values and passing to show result
	    		multiply(FirstValue.getText(), SecondValue.getText());
	    	}
        });

        //Adding listener to button
        add.setOnClickListener(new View.OnClickListener() {
	    	public void onClick(View v) {
	    		//Getting first & second values and passing to show result
	    		add(FirstValue.getText(), SecondValue.getText());
	    	}
        });
        
        //Adding listener to button
        subtract.setOnClickListener(new View.OnClickListener() {
	    	public void onClick(View v) {
	    		//Getting first & second values and passing to show result
	    		subtract(FirstValue.getText(), SecondValue.getText());
	    	}
        });

        //Adding listener to button
        divide.setOnClickListener(new View.OnClickListener() {
	    	public void onClick(View v) {
	    		//Getting first & second values and passing to show result
	    		divide(FirstValue.getText(), SecondValue.getText());
	    	}
        });
 }

 //Showing multiply results
 protected void multiply(Editable first, Editable second) 
 {
	 float num1 = Float.parseFloat(first.toString());
	 float num2 = Float.parseFloat(second.toString());
	 float result = num1 * num2;
	 Result.setText(String.valueOf(result));
 }
 
 //Showing multiply results
 protected void add(Editable first, Editable second) 
 {
	 float num1 = Float.parseFloat(first.toString());
	 float num2 = Float.parseFloat(second.toString());
	 float result = num1 + num2;
	 Result.setText(String.valueOf(result));
 }
 
 //Showing multiply results
 protected void subtract(Editable first, Editable second) 
 {
	 float num1 = Float.parseFloat(first.toString());
	 float num2 = Float.parseFloat(second.toString());
	 float result = num1 - num2;
	 Result.setText(String.valueOf(result));
 }
 
 //Showing multiply results
 protected void divide(Editable first, Editable second) 
 {
	 float num1 = Float.parseFloat(first.toString());
	 float num2 = Float.parseFloat(second.toString());
	 float result = num1 / num2;
	 Result.setText(String.valueOf(result));
 }
}
